<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>服务申请</title>
    <link rel="stylesheet" href="/pear/component/layui/css/layui.css">
    <script src="/pear/component/layui/layui.js"></script>
</head>
<body>
<div style="margin-right: 15px">
    <div class="layui-form-item" style="margin-top: 30px">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text"lay-verify="required" id="userName" value="申请的用户名" readonly autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">申请日期</label>
        <div class="layui-input-block">
            <input type="text" readonly  id="calender" class="layui-input" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">需求说明</label>
        <div class="layui-input-block">
            <textarea name="desc" readonly placeholder="请输入问题的详细描述" class="layui-textarea" id="content"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择日期</label>
        <div class="layui-input-block">
            <input type="text" id="dealCalender" class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">预计花费</label>
        <div class="layui-input-block">
            <input type="text" id="predictCost" class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">服务时长</label>
        <div class="layui-input-block">
            <input type="text" id="serviceTime" class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo" id="btnClick">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <div id="customerId" style="display: none"></div>
</div>
<script>

    layui.use(['form','laydate','layer'], function(){
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            $ = layui.jquery;
        laydate.render({
            elem: '#dealCalender'
            ,type: 'datetime'
        });



        //监听提交
        $("#btnClick").click(()=>{
            var userName = $('#userName').val(); //用户名
            var dealCalender = $('#dealCalender').val(); // 处理日期
            var predictCost = $('#predictCost').val(); // 预计花费
            var serviceTime = $('#serviceTime').val(); // 服务时间
            var customerId = $('#customerId').val(); // Id
            var Dealed = "已处理";
            console.log(customerId);
            // 发起ajax请求 对应服务记录表,"customerId":customerId,
            $.ajax({
                url:'/apply/insertApply',
                data:{"customerId":customerId, "userName":userName,"dealCalender":dealCalender,
                    "predictCost":predictCost,"serviceTime":serviceTime, "Dealed":Dealed},
                success:function (data) {
                    console.log(data);
                    if (data.status=="成功"){
                        console.log("&&&&&&&&&&&&&&&&&&&&&")
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }else {
                        layer.msg('申请失败');
                    }
                }
            })
        })
        // form.on('submit(formDemo)', function(data){
        //
        // });
    });
</script>

</body>
</html>